home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Tools&Utilities / TouchMe 1.2□ / touchMe 1.2 Folder / touchMe source codes / CW11 PP source / source / Common Lib / UMacOSTools.cp < prev    next >
Encoding:
Text File  |  1997-04-25  |  4.8 KB  |  201 lines  |  [TEXT/CWIE]

  1. // ==================================================
  2. //    UMacOSTools.cp
  3. //    Copyright (C) 1997 Mizutori Tetsuya
  4. //    March 24, 1997, April 9, 1997.
  5. // ==================================================
  6. //    All documents are pretty-printed in 10-point Geneva font.
  7.  
  8. #include <Finder.h>
  9. #include <UKeyFilters.h>
  10.  
  11. #include "UMacOSTools.h"
  12.  
  13.  
  14. // ==================================================
  15. //        • Constructors
  16. // ==================================================
  17.  
  18. // --------------------------------------------------
  19. //        • UMacOSTools
  20. // --------------------------------------------------
  21.  
  22. UMacOSTools::UMacOSTools()
  23. {
  24. }
  25.  
  26.  
  27. // --------------------------------------------------
  28. //        • UMacOSTools
  29. // --------------------------------------------------
  30.  
  31. UMacOSTools::~UMacOSTools()
  32. {
  33. }
  34.  
  35.  
  36. // ==================================================
  37. //        • Member functions (keyboard status)
  38. // ==================================================
  39.  
  40. // --------------------------------------------------
  41. //        • IsCommandPeriod
  42. // --------------------------------------------------
  43. // Check keyboard status wheather cmd-period is pressed.
  44.  
  45. Boolean
  46. UMacOSTools::IsCommandPeriod( void )
  47. {
  48.     Boolean        result = false;
  49.  
  50.     Boolean        gotEvent;
  51.     EventRecord    theMacOSEvent;
  52. //    gotEvent = ::EventAvail( everyEvent, &theMacOSEvent );
  53.     gotEvent = ::EventAvail( keyDownMask, &theMacOSEvent );
  54.  
  55.     if ( gotEvent && UKeyFilters::IsCmdPeriod( theMacOSEvent ) ) {
  56.     //    ::FlushEvents( everyEvent, 0 );
  57.     //    ::FlushEvents( keyDownMask, 0 );
  58.         ::WaitNextEvent( keyDownMask, &theMacOSEvent,  0, NULL );
  59.         result = true;
  60.     }
  61.  
  62.     return result;
  63. }
  64.  
  65.  
  66.  
  67. // --------------------------------------------------
  68. //        • IsModifierKeyPressed
  69. // --------------------------------------------------
  70. // Check keyboard status wheather a modifier key is pressed.
  71. //    cmdKey        = 0x0100
  72. //    shiftKey        = 0x0200
  73. //    alphaLock        = 0x0400
  74. //    optionKey        = 0x0800
  75. //    controlKey        = 0x1000
  76.  
  77. Boolean
  78. UMacOSTools::IsModifierKeyPressed(
  79.     Uint32        inModifierKey )
  80. {
  81.     EventRecord    theMacOSEvent;
  82.     Boolean        gotEvent = ::EventAvail( everyEvent, &theMacOSEvent );
  83.  
  84.     return IsModifierKeyPressed( theMacOSEvent, inModifierKey );
  85. }
  86.  
  87.  
  88. Boolean
  89. UMacOSTools::IsModifierKeyPressed(
  90.     const EventRecord &    inMacOSEvent,
  91.     Uint32            inModifierKey )
  92. {
  93.     return ( (inMacOSEvent.modifiers & inModifierKey) != 0 );
  94. }
  95.  
  96.  
  97. // ==================================================
  98. //        • Member functions (4-char code string)
  99. // ==================================================
  100.  
  101. // --------------------------------------------------
  102. //        • FourCharCodeToPStr
  103. // --------------------------------------------------
  104. //    Convert a four character code to a Pascal string and return a pointer to the string.
  105.  
  106. StringPtr
  107. UMacOSTools::FourCharCodeToPStr(
  108.     FourCharCode    inCode,
  109.     StringPtr        outString )
  110. {
  111.     outString[0] = sizeof( FourCharCode );
  112.     for ( long i = 1; i <= outString[0]; i++ ) outString[i] = ' ';
  113.  
  114.     ::BlockMoveData( &inCode, &outString[1], outString[0] );
  115.  
  116.     return outString;
  117. }
  118.  
  119.  
  120. // --------------------------------------------------
  121. //        • PStrToFourCharCode
  122. // --------------------------------------------------
  123. //    Convert an Pascal string to a four character code.
  124.  
  125. void
  126. UMacOSTools::PStrToFourCharCode(
  127.     ConstStringPtr    inString,
  128.     FourCharCode &    outCode )
  129. {
  130.     outCode = '    ';    // 4 white spaces
  131.  
  132.     long    len = ( inString[0] < sizeof(OSType) ? inString[0] : sizeof(OSType) );
  133.  
  134.     ::BlockMoveData( &inString[1], &outCode, len );
  135. }
  136.  
  137.  
  138. // ==================================================
  139. //        • Member functions (Finder flags)
  140. // ==================================================
  141.  
  142. #ifdef COMMENT // Finder Flags
  143.     kIsOnDesk                    = 0x1,
  144.     kColor                    = 0xE,
  145.     kIsShared                    = 0x40,
  146.     kHasBeenInited                = 0x100,
  147.     kHasCustomIcon                = 0x400,
  148.     kIsStationary                = 0x800,
  149.     kNameLocked                = 0x1000,
  150.     kHasBundle                = 0x2000,
  151.     kIsInvisible                = 0x4000,
  152.     kIsAlias                    = 0x8000,
  153. #endif // COMMENT
  154.  
  155. // --------------------------------------------------
  156. //        • SetFinderFlag
  157. // --------------------------------------------------
  158. //    Set a Finder flag.
  159.  
  160. void
  161. UMacOSTools::SetFinderFlag(
  162.     FSSpec &        ioMacFSSpec,
  163.     Uint16        inFinderFlag,
  164.     Boolean        inSetting )
  165. {
  166.     FInfo        theFinderInfo;
  167.     OSErr    err;
  168.     err = ::FSpGetFInfo( &ioMacFSSpec, &theFinderInfo );
  169.     if ( err != noErr ) return;
  170.  
  171.     if ( inSetting ) {
  172.         theFinderInfo.fdFlags |= inFinderFlag;
  173.     } else {
  174.         theFinderInfo.fdFlags &= ~inFinderFlag;
  175.     }
  176.  
  177.     err = ::FSpSetFInfo( &ioMacFSSpec, &theFinderInfo );
  178. }
  179.  
  180.  
  181. // --------------------------------------------------
  182. //        • HasFinderFlag
  183. // --------------------------------------------------
  184. //    Return whether a Finder flag is on or off
  185.  
  186. Boolean
  187. UMacOSTools::HasFinderFlag(
  188.     FSSpec &        inMacFSSpec,
  189.     Uint16        inFinderFlag )
  190. {
  191.     FInfo        theFinderInfo;
  192.     OSErr    err;
  193.     err = ::FSpGetFInfo( &inMacFSSpec, &theFinderInfo );
  194.     if ( err != noErr ) return false;
  195.  
  196.     return ((theFinderInfo.fdFlags & inFinderFlag) == inFinderFlag);
  197. }
  198.  
  199.  
  200. // end of program
  201.